<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.transcargo.users.Contact" %>
<%@ page import="com.transcargo.users.User" %>
<%@ page import="com.transcargo.users.Transport" %>
<%@ page import="com.transcargo.errors.ErrorList" %>
<%@ page import="java.util.HashMap" %>
<%@include file="header.jsf"%>
<%@include file="session.jsf"%>
<%
    if (User_Id <= 0) {
        response.sendRedirect("auth.jsp");
        return;
    }
	String id = request.getParameter("id");
	if (id == null || id.length() == 0 || Integer.parseInt(id) == 0) {
		response.sendRedirect("trucks.jsp");
		return;
	}
	HashMap<String,String> loads = new HashMap<String,String>();
	int Id = Integer.parseInt(id);
	Transport tr = user.getTransport(Id, dbase);
	int[] load = tr.getLoading();
	for (int i = 0; i < load.length; i++) {
		loads.put(Integer.toString(load[i]),"true");
	}

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  	<head><title>TransCargo</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function gouser()
{
    window.location='trucks.jsp';
}
</script>
	<script type="text/javascript" src="forms.js"></script>
	<link type="text/css" href="transcargo.css" rel="stylesheet"/>
  </head>
  <body>
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr><td>
			<%@include file="page_header.jsf"%>
        </td></tr>
        <tr><td align="center">
            Изменение параметров транспорта для <%=user.getName()%><br><br>
			<div id="ErrorPlaceHolder" class="errorString"></div>
            <form action="EditTruckAction" method="POST" target="ifPost">
			<input type="hidden" name="id" value="<%=Id %>">
			<br><b><%=tr.getName() %></b>
            <table border="0" cellpadding="0" cellspacing="0">
                <tr><td class="tdFormSearch"><b>Тип транспорта:</b></td><td align="left"><select name="cargo_type" id="cargo_type" class="selNormal">
					<%
					        iter = null;
					        list = dbase.execute("SELECT id, name from transport_type");
					        if (list != null) iter = list.iterator();
					        if (iter != null) {
					            while (iter.hasNext()) {
					                String[] str = iter.next();
					                if (Integer.parseInt(str[0]) == tr.getType()) {
						                %><option value="<%=str[0]%>" selected><%=str[1]%></option><%
					                } else {
					                	%><option value="<%=str[0]%>"><%=str[1]%></option><%
					                }
					            }
					        }
					%>
				    </select></td></tr>
                <tr><td class="tdFormSearch"><b>Тип загрузки:</b></td><td align="left">
                    <%
				        iter = null;
				        list = dbase.execute("SELECT id, name from transport_loading");
				        if (list != null) iter = list.iterator();
			            while (iter.hasNext()) {
			                String[] str = iter.next();
			                if (loads.containsKey(str[0])) {
			                	%><input type="checkbox" name="load<%=str[0]%>" checked><%=str[1]%><br><%
			                } else {
			                	%><input type="checkbox" name="load<%=str[0]%>"><%=str[1]%><br><%
			                }
			            }
				%>
                </td></tr>
                <tr class="tdFormSearch"><td><b>Объем:</b></td><td align="left"><input name="volume" size="10" value="<%=tr.getVolume() %>"> м<sup>3</sup></td></tr>
                <tr class="tdFormSearch"><td><b>Тоннаж:</b></td><td align="left"><input name="tonnage" size="10" value="<%=tr.getTonnage() %>"> т.</td></tr>
                <tr class="tdFormSearch"><td>Длина:</td><td align="left"><input name="length" size="10"<% if (tr.getLength() > 0) out.print(" value=\""+tr.getLength()+"\""); %>> м.</td></tr>
                <tr class="tdFormSearch"><td>Высота:</td><td align="left"><input name="height" size="10"<% if (tr.getHeight() > 0) out.print(" value=\""+tr.getHeight()+"\""); %>> м.</td></tr>
                <tr class="tdFormSearch"><td>Ширина:</td><td align="left"><input name="width" size="10"<% if (tr.getWidth() > 0) out.print(" value=\""+tr.getWidth()+"\""); %>> м.</td></tr>
                <tr class="tdFormSearch"><td>TIR Carnet:</td><td align="left"><input type="checkbox" name="tir"<% if (tr.getTIR()) out.print(" checked"); %>></td></tr>
                <tr class="tdFormSearch"><td>EKMT:</td><td align="left"><input type="checkbox" name="ekmt"<% if (tr.getEKMT()) out.print(" checked"); %>></td></tr>
                <tr class="tdFormSearch"><td>Класс ADR:</td><td align="left"><select name="adr">
                    <option value="">-</option>
                    <option value="1"<% if (tr.getADR() == 1) out.print(" selected"); %>>1</option>
                    <option value="2"<% if (tr.getADR() == 2) out.print(" selected"); %>>2</option>
                    <option value="3"<% if (tr.getADR() == 3) out.print(" selected"); %>>3</option>
                    <option value="4"<% if (tr.getADR() == 4) out.print(" selected"); %>>4</option>
                    <option value="5"<% if (tr.getADR() == 5) out.print(" selected"); %>>5</option>
                    <option value="6"<% if (tr.getADR() == 6) out.print(" selected"); %>>6</option>
                    <option value="7"<% if (tr.getADR() == 7) out.print(" selected"); %>>7</option>
                    <option value="8"<% if (tr.getADR() == 8) out.print(" selected"); %>>8</option>
                    <option value="9"<% if (tr.getADR() == 9) out.print(" selected"); %>>9</option>
                </select></td></tr>
                <tr><td class="tdFormSearch"><input type="submit" value="Продолжить"></td><td align="left"><input type="submit" value="Отмена" onclick="gouser();return false;"></td></tr>
            </table>
            </form>
        </td></tr>
        </table>
	<iframe name="ifPost" id="ifPost" width="0" height="0" style="visibility: hidden;width: 0;height: 0;" onload="handlePost(this);" onload="handlePost(this);"></iframe>

  </body>
</html>
